﻿using BlazorApp3.Shared;
using System.Net.Http.Json;

namespace BlazorApp3.Client.Infrastructure.Services;

public class WeatherforecaseClientService : IWeatherforecaseService
{
    private readonly HttpClient _httpClient;
    private readonly IUrls _urlService;

    public WeatherforecaseClientService(HttpClient httpClient, IUrls urlService)
    {
        _httpClient = httpClient;
        _urlService = urlService;
        _httpClient.BaseAddress = new Uri(_urlService.WeatherforcastUrl);
    }

    public async ValueTask<WeatherForecast[]> GetList()
    {
        return await _httpClient.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast")
            ?? new WeatherForecast[] { };
    }
}